package com.ayou.eggguard.farm.service.impl;

import com.ayou.common.utils.PageBean;
import com.ayou.eggguard.farm.mapper.DrugMapper;
import com.ayou.eggguard.farm.pojo.Drug;
import com.ayou.eggguard.farm.service.DrugService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DrugServiceImpl implements DrugService {
    @Autowired
    private DrugMapper drugMapper;

    @Override
    public PageBean<Drug> getDrugs(Integer pageNumb, Integer pageSize, String drugNumber) {
        PageBean<Drug> pb=new PageBean<>();
        PageHelper.startPage(pageNumb,pageSize);
        List<Drug> list=drugMapper.getDrugs(drugNumber);
        Page<Drug> p= (Page<Drug>) list;
        pb.setTotal(p.getTotal());
        pb.setItems(p.getResult());

        return pb;
    }

    @Override
    public void add(Drug drug) {
        drugMapper.add(drug);
    }

    @Override
    public void update(Drug drug) {
        drugMapper.update(drug);
    }

    @Override
    public void delete(Integer id) {
        drugMapper.delete(id);
    }
}
